<script setup>
import * as api from "@/api/v-wkf-service/wkf-space/my-done";
import FlowBox from "@/views/v-wkf-service/flow/wkf-flow/flow-box.vue";
/**
 * 组件挂载后
 */
onMounted(() => {
  init()
})

/**
 * 列表数据
 */
const tableData = ref([])

/**
 * loading状态
 */
const loading = ref({
  tableLoading: false,// 列表loading
})

const showFlowBox = ref(false)

const rowData = ref({})

/**
 * 计算表格属性
 */
const tableInfo = computed(()=>{
  const tableProps = {
    data: tableData.value,
    loading: loading.value.tableLoading,
    rowConfig: { keyField: 'id' },
    checkboxConfig: { highlight: false, reserve: true },
    showSelectCount: false,
    showExportBtn: false,
  }
  return { ...tableProps }
})

/**
 * 分页参数
 */
const pageQuery = reactive({
  page: 1,
  limit: 50,
  total: 0,
  orders: [],
  filters: [],
  condition: {
    key: "",
  },
})

/**
 * 组件初始化调用函数
 */
const init = () => {
  init_PageQuery()
}

/**
 * 分页查询
 */
const init_PageQuery = async () => {
  loading.value.tableLoading = true
  const { code, data } = await api.getDoneList(pageQuery)
  if (code === 200) {
    loading.value.tableLoading = false
    tableData.value = data.records
    pageQuery.total = data.total
  }
}

const handleProcess = (row) => {
  showFlowBox.value = true
  rowData.value = row
}

/**
 * 组件对外提供可访问数据
 */
defineExpose({
  init_PageQuery,
})

</script>

<template>
  <div class="my-done-box flex flex-col">
    <div class="btn">
      <div class="flex align-center">
        <label class="label">{{'\u2003'}}关键字{{'\u2003'}}</label>
        <el-input
            v-model="pageQuery.condition.key"
            style="width: 180px;" placeholder="请输入关键字"
            @keyup.enter="init_PageQuery" @clear="init_PageQuery" clearable
        />
        <div class="el-button" style="display: none"></div>
        <el-button type="primary" @click="init_PageQuery">
          <template #icon><i-ep-search /></template>搜索
        </el-button>
      </div>
    </div>
    <v-table
        v-model="pageQuery"
        :marginBottomHeight="295"
        :table-info="tableInfo"
        :column-info="api.columnInfo"
        @query="init_PageQuery"
    >
      <template #startUser="{row}">
        {{ row.startUser.name }}
      </template>
      <template #operate="{row}">
        <el-button type="primary" :text="true" @click="handleProcess(row)">
          <template #icon><i-ep-edit /></template>详情
        </el-button>
      </template>
    </v-table>
    <FlowBox
        v-if="showFlowBox"
        v-model="showFlowBox"
        :hasTempSave="false"
        componentUrl="v-wkf-service/flow-test/flow-test-form"
        flowKey="work_handover"
        :formType="4"
        dialogTitle="工作交接审批"
        :paramObj="rowData"
    ></FlowBox>
  </div>
</template>

<style scoped lang="scss">
.my-done-box {
  padding: 10px;
  .btn {
    text-align: right;
    position: absolute;
    top: -35px;
    right: 0;
    padding-right: 20px;
  }
  .container {
    :deep(.el-tag) {
      cursor: pointer;
    }
    :deep(.el-button) {
      padding: 0;
    }
  }
}
</style>
